<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Insert title here</title>
		<link rel="stylesheet" href="../css/reg.css" type="text/css"></link>
		<script type="text/javascript"
			src="../js/jquery-validation-1.10.0/lib/jquery-1.7.2.js"></script>
		<script type="text/javascript">  
		window.onload = function() {
 	 	  $("#password1").attr("disabled",true);
 	 	  $("#password2").attr("disabled",true);
 	 	 
		}
		function checkPassword(){
		
			var pwd=$("#password").val();
			var flag=false;
			$.ajax({
  			type: "POST",
   			url: "<%=path%>/changeuser/changeuser!checkUserPassWord.action",
   			async:false,
   			data: "uid="+$("#uid").val()+"&pwd="+$("#password").val(),
   			success:function(txt){
   				if($.parseJSON(txt).flag=="success"){
   					$("#passwordSpan").html("<font color='red'>密码正确</font>");
   					 $("#password1").attr("disabled",false);
 	 	 			 
 	 	 			 flag=true;
   				}else{
   					$("#passwordSpan").html("<font color='red'>密码不正确</font>");
   					 $("#password1").attr("disabled",true);
 	 	  			 $("#password2").attr("disabled",true);
 	 	  			 flag=false;
   				}
   			}
			});
			return flag;
		}
		
	function checkPassWord(){
		
		checkChangePassWord();
		var testPassword=/^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~\_]{6,20}$/;
		if($.trim($("#password1").val())==""){
		
			$("#password1Span").html("<font color='red'>请输入密码</font>");
			
			return false;
		}else if(testPassword.test($.trim($("#password1").val()))){
			$("#password1Span").html("<font color='red'>密码可以使用</font>");
			$("#password2").attr("disabled",false);
			return true;
		}else{
			$("#password1Span").html("<font color='red'>请输入正确格式的密码</font>");
			
			return false;
		}
		
	}
		function checkChangePassWord(){
			var pwd1= $("#password1").val();
			var pwd2= $("#password2").val();
			if(pwd1==pwd2){
				$("#password1Span").html("<font color='red'>两次密码一致</font>");
				return true;
			}else{
				$("#password1Span").html("<font color='red'>两次密码不一致</font>");
				return false;
			
			}
		}
		function formSubmit(){
			alert(checkPassword()&&checkChangePassWord());
			if(checkPassword()&&checkChangePassWord()){
				$("#changePwdForm").submit();
			
			}else{
				return;
			}
			
		}
		

		</script>
		<link rel="stylesheet" href="../css/Style.css" type="text/css"></link>
	</head>
	<body>
		<table width="980px" border="0" cellspacing="0" cellpadding="0"
			align="center">
			<tr>
				<td width="50%" height=80 rowspan=2>
					<div class=Mleft>

						<img src="../imgs/logo.gif" border=0>
					</div>
				</td>
				<td width="50%">
					<span id=AjaxShow></span>
					<br>
				</td>
			</tr>
			<tr>
				<td valign=bottom align=right>
					欢迎您：
					<strong><font color=red>${user.name }</font> </strong>
					<a href=/login.asp?Action=Logout target=_parent>退出</a>
				</td>
			</tr>
		</table>
		<table id=div border="0" cellspacing="0" cellpadding="0" align=center>
			<tr>
				<td>
					<img src=../imgs/center_top.gif>
				</td>
			</tr>
			<tr>
				<td
					style='padding: 5px; border-left: 1px #CCCCCC solid; border-right: 1px #CCCCCC solid'>
					<table border="0" cellspacing="0" cellpadding="0" align=center>
						<tr>
							<td width="155" valign=top>
								<jsp:include page="../frame/left.jsp" />
							</td>
							<td width="810" valign="top">
								<!-- right -->
								<div class="UserPath">
									您的位置：
									<a href="<%=path%>/changeuser/changeuser!showUserInfo.action">会员中心</a>
									&gt;
									<a href="<%=path%>/user/changeUserPassWord.jsp">密码修改</a>
								</div>
								<table width="100%" cellpadding="2" cellspacing="1" border="0"
									align="center" class="td1">
									<tbody>
										<tr class="td2">
											<td>
												&nbsp;
												<a href="<%=path%>/user/changeUserInfo.jsp">修改资料</a>|
												<a href="<%=path%>/user/changeUserPassWord.jsp">修改密码</a>|

												<a href="<%=path%>/user/changeUserAvatar.jsp">修改头像</a>
											</td>
										</tr>
									</tbody>
								</table>
								<form method="post"
									action="<%=path%>/changeuser/changeuser!updateUserPassWord.action"
									id="changePwdForm">
									<table width="100%" border="0" cellspacing="1" cellpadding="3"
										class="td1" align="center">
										<input type="hidden" id="uid" name="uid" value="${user.id }" />
										<tbody>
											<tr>
												<td class="td4" colspan="3">
													安全设置
												</td>
											</tr>
											<tr class="td2">
												<td width="30%">
													<strong>原始密码</strong>
													<font class="Font2"><b>*</b> </font>
												</td>
												<td width="70%">
													<input name="password" id="password" size="20"
														maxlength="50" onblur="checkPassword()" type="password">
													<span id="passwordSpan"></span>
												</td>

											</tr>
											<tr class="td2">
												<td>
													<strong>新密码</strong>
													<br>

												</td>
												<td>
													<input name="pwd" id="password1" size="20" maxlength="50"
														type="password" onChange="checkPassWord()">
													<span id="password1Span"></span>
												</td>

											</tr>
											<tr class="td2">
												<td>
													<strong>确认新密码</strong>
													<br>

												</td>
												<td>
													<input name="pwd2" id="password2" size="20" maxlength="50"
														type="password" onblur="checkChangePassWord()">


												</td>
											</tr>

											<tr class="td2">
												<td></td>
												<td>
													<input type="button" value="确定修改" onclick="formSubmit()">
												</td>
											</tr>

										</tbody>
									</table>
								</form>
								<!-- right end -->
							</td>
						</tr>

					</table>
				</td>
			</tr>
			<tr>
				<td>
					<img src="../imgs/center_bottom.gif">
				</td>
			</tr>
		</table>


	</body>
</html>
